package offer;

public class Singleton4 {
    private static Singleton4 instance;

    private Singleton4() {

    }

    public static Singleton4 getInstance() {
        if (instance == null) {
            synchronized (Singleton4.class) {
                if (instance == null) {
                    try {
                        // 这个地方线程休眠1s是为了测试多线程情况下的单例模式
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    instance = new Singleton4();
                }
            }
        }

        return instance;
    }
}
